package com.example.mall.web.controller;

import com.example.mall.domain.PaymentPlatforms;
import com.example.mall.dto.PaymentPlatformsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PaymentPlatformsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPaymentPlatformsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paymentPlatforms")
public class PaymentPlatformsController {

    @Autowired
    public IPaymentPlatformsService paymentPlatformsService;

    /**
     * 分页查询支付平台表信息
     * @param paymentPlatformsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付平台表信息",notes = "分页查询支付平台表信息",httpMethod = "GET")
    public JSONResult queryPage(PaymentPlatformsQuery paymentPlatformsQuery){
        PageDTO<PaymentPlatformsDto> paymentPlatformsDtoPageDTO = paymentPlatformsService.queryPage(paymentPlatformsQuery);
        return JSONResult.success("查询成功",paymentPlatformsDtoPageDTO);
    }

    /**
     * 根据id查询支付平台表信息
     * @param platformId
     * @return
     */
    @GetMapping("query/{platformId}")
    @ApiOperation(value = "根据id查询支付平台表信息",notes = "根据id查询支付平台表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("platformId")Long platformId){
        //1.根据id查询用户信息
        if (platformId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PLATFORMID_NOT_ID);
        }
        PaymentPlatforms paymentPlatforms = paymentPlatformsService.getById(platformId);
        return JSONResult.success("查询成功",paymentPlatforms);
    }

    /**
     * 根据id查询支付平台表信息
     * @param platformId
     * @return
     */
    @GetMapping("queryPaymentPlatformsById/{platformId}")
    @ApiOperation(value = "根据id查询支付平台表信息",notes = "根据id查询支付平台表信息",httpMethod = "GET")
    public JSONResult queryPaymentPlatformsById(@PathVariable("platformId")Long platformId){
        //1.根据id查询用户信息
        if (platformId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PLATFORMID_NOT_ID);
        }
        PaymentPlatforms paymentPlatforms = paymentPlatformsService.queryPaymentPlatformsById(platformId);
        return JSONResult.success("查询成功",paymentPlatforms);
    }

    /**
     * 查询全部支付平台表信息
     * @param
     * @return
     */
    @GetMapping("queryPaymentPlatformsList")
    @ApiOperation(value = "查询全部支付平台表信息",notes = "查询全部支付平台表信息",httpMethod = "GET")
    public JSONResult queryPaymentPlatformsList(){
        List<PaymentPlatforms> paymentPlatforms = paymentPlatformsService.queryPaymentPlatformsList();
        return JSONResult.success("查询成功",paymentPlatforms);
    }

    /**
     * 新增支付平台表
     * @param paymentPlatformsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付平台表",notes = "新增支付平台表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PaymentPlatformsDto paymentPlatformsDto){
        paymentPlatformsService.insert(paymentPlatformsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付平台表信息
     * @param paymentPlatformsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付平台表信息",notes = "修改支付平台表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PaymentPlatformsDto paymentPlatformsDto){
        paymentPlatformsService.update(paymentPlatformsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付平台表信息
     * @param platformId
     * @return
     */
    @PostMapping("delete/{platformId}")
    @ApiOperation(value = "删除支付平台表信息",notes = "删除支付平台表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("platformId") Long platformId) {
        paymentPlatformsService.delete(platformId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付平台表信息
     * @param platformIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付平台表信息",notes = "批量删除支付平台表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> platformIds) {
        paymentPlatformsService.deleteBatch(platformIds);
        return JSONResult.success("批量删除成功");
    }
}
